<?php

namespace Beerus\Modules\Designer\Actions;

use Beerus\Modules\Designer\Controllers\KaDesignerController;
use Doraemon\cache\Queue;
use Doraemon\cache\User as CacheUser;
use Doraemon\model\AdmOperateLog;
use Doraemon\model\KaDesigner;
use Doraemon\tools\Log;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;
use Doraemon\model\AdmRecommendUser;
use Doraemon\model\AdmBestUser;
use Doraemon\model\Member;
use Doraemon\service\KaManage\Combo;

class ForcedEffect0 extends RowAction
{
    public $name = '强制生效';
    const TOAST_ALERT = '合同金额为0，是否确认将合同设为生效？';

    public function handle($id)
    {
        $update_data['data_status'] = KaDesigner::STATUS_EFFECT;
        $ka_result = KaDesigner::updateById($id,$update_data);
        if ($ka_result){
            // 初始化设计师KA广告套餐信息
            if (!Combo::initDesignerComboDetail($id)) {
                Log::info("设计师KA广告套餐信息初始化失败，订单ID：{$id}");
            }
            //增加子账号权益
            KaDesignerController::CreatEquity($id);
            return $this->response()->success('强制生效成功(*^__^*)')->refresh();
        }else{
            return $this->response()->error('强制生效失败,请稍后重试o(TωT)o');
        }

    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}
